class OceanBaseDiscovery:
    def __init__(self, config):
        self.conn = OBConnection(config)
        
    def discover_resources(self):
        """发现OceanBase集群资源"""
        return {
            "tenants": self._get_tenants(),
            "databases": self._get_databases(),
            "tables": self._get_tables()
        }
    
    def _get_tenants(self):
        """获取租户信息"""
        with self.conn.cursor() as cur:
            cur.execute("SHOW TENANTS")
            return [{
                "name": row["TENANT_NAME"],
                "type": row["TENANT_TYPE"],
                "charset": row["CHARSET"]
            } for row in cur.fetchall()]

    def _get_databases(self):
        """获取数据库信息"""
        with self.conn.cursor() as cur:
            cur.execute("SHOW DATABASES")
            return [{
                "name": row["DATABASE_NAME"],
                "charset": row["DEFAULT_CHARSET"],
                "collation": row["DEFAULT_COLLATION"]
            } for row in cur.fetchall()]